import React from 'react';
import moment from 'moment';
import { isNil } from 'lodash';

import { Tooltip, Icon } from 'antd';

import { numberFormat } from '@/utils/formatterUtil';

import { MONTHList } from '@/pages/SalaryManage/utils/staticList';
import { housePlaceEnum, sexEnum } from '@/pages/SalaryManage/enum';
import { SINGAPORE_CODE } from '@/pages/SalaryManage/constant/countryRegion';

import EmptyPlaceHolder from '@/pages/SalaryManage/components/EmptyPlaceHolder';

import styles from '@/pages/SalaryManage/MySalary/index.less';

// 基础信息字段配置
const BASE_INFO_MAP = {
    employeeNo: '工号',
    startDate: '入职日期',
    birthday: '出生日期',
    name: '姓名',
    workAddress: '工作地点',
    cardName: '证照类型',
    departmentName: '组织机构',
    education: '学历',
    cardNo: '身份证号',
    manager: '主管',
    email: '联系邮箱',
    socialCity: '参保城市',
    positionName: '职位',
    telephone: '联系手机',
    housePlace: '社保方案',
    rankName: '职级',
    bankNo: '银行卡号',
    socialYearMonth: '起始缴交月份',
    statusName: '状态',
    bankName: '开户行'
    // fundNo: '公积金账号'
};

// 基础信息字段-with新加坡
const SIN_BASE_INFO_MAP = {
    employeeNo: '工号',
    departmentName: '组织机构',
    bankNo: '银行卡号',
    englishName: '英文名',
    workAddress: '工作地点',
    bankName: '开户行',
    name: '中文姓名',
    startDate: '入职日期',
    nation: '国籍',
    // aliasName: '昵称',
    positionName: '职位',
    singaporeidTypeName: '当前居民身份',
    sex: '性别',
    rankName: '职级',
    identityidNo: '证照号码',

    // marriage: '婚姻', // 还没有
    manager: '主管',
    prAcquisitionDate: 'PR取得时间',
    birthday: '出生日期',
    statusName: '状态',
    cpfPayName: 'CPF类型',
    religionName: '宗教',
    education: '学历',
    singaporeRaceName: '种族'
};

// 基础信息-根据国别取值
const baseInfoOfCountry = val => {
    switch (val) {
        case SINGAPORE_CODE:
            return SIN_BASE_INFO_MAP;
        default:
            return BASE_INFO_MAP;
    }
};

// 薪资历史记录-基础配置
const HISTORY_RECORD_LIST = [
    {
        key: 'salaryRecords',
        name: '薪资记录'
    },
    {
        key: 'kpiRecords',
        name: '绩效系数记录',
        columns: [
            {
                title: '序号',
                dataIndex: 'no',
                key: 'no',
                width: 80,
                align: 'center',
                render: (t, r, i) => i + 1
            },
            {
                title: '所属月份',
                dataIndex: 'month',
                key: 'month',
                width: 120,
                render: t => (MONTHList[t - 1] ? MONTHList[t - 1].monthName : <EmptyPlaceHolder />)
            },
            {
                title: '绩效薪资类型',
                dataIndex: 'salaryItemName',
                key: 'salaryItemName',
                width: 200,
                align: 'center',
                render: text => <EmptyPlaceHolder value={text} />
            },
            {
                title: '开始区间',
                align: 'center',
                render: (text, record) =>
                    `${record.kpiStartYear}-${(record.kpiStartMonth < 10 ? '0' : '') + record.kpiStartMonth}`
            },
            {
                title: '结束区间',
                align: 'center',
                render: (text, record) =>
                    `${record.kpiEndYear}-${(record.kpiStartMonth < 10 ? '0' : '') + record.kpiEndMonth}`
            },
            {
                title: '绩效系数',
                dataIndex: 'kpiNum',
                key: 'kpiNum',
                align: 'center',
                render: text => <EmptyPlaceHolder value={text} />
            },
            {
                title: '备注',
                dataIndex: 'remark',
                key: 'remark',
                align: 'center',
                render: text => <EmptyPlaceHolder value={text} />
            }
        ]
    },
    {
        key: 'attendRecords',
        name: '考勤记录'
    },
    {
        key: 'taxRecords',
        name: '专项扣款扣除',
        countryCode: 'CN',
        columns: [
            {
                title: '月份',
                width: 120,
                dataIndex: 'yearMonth',
                align: 'left',
                render: (text, record) =>
                    record.year ? `${record.year}-${(record.month < 10 ? '0' : '') + record.month}` : '合计'
            },
            {
                title: '合计金额',
                width: 120,
                align: 'right',
                children: [
                    {
                        title: '当月金额',
                        dataIndex: 'encryptCurrSpecialAmt',
                        key: 'encryptCurrSpecialAmt',
                        width: 120,
                        columnType: 2,
                        render: t => <NumberTypeTd value={t} />,
                        align: 'right'
                    }
                ]
            },
            {
                title: '子女教育',
                width: 120,
                align: 'right',
                children: [
                    {
                        title: '当月金额',
                        dataIndex: 'encryptCurrChildEducationAmt',
                        key: 'encryptCurrChildEducationAmt',
                        width: 120,
                        columnType: 2,
                        render: t => <NumberTypeTd value={t} />,
                        align: 'right'
                    }
                ]
            },

            {
                title: '继续教育',
                width: 120,
                align: 'right',
                children: [
                    {
                        title: '当月金额',
                        dataIndex: 'encryptCurrContinueEducationAmt',
                        key: 'encryptCurrContinueEducationAmt',
                        width: 120,
                        columnType: 2,
                        render: t => <NumberTypeTd value={t} />,
                        align: 'right'
                    }
                ]
            },
            {
                title: '住房贷款利息',
                width: 120,
                align: 'right',
                children: [
                    {
                        title: '当月金额',
                        dataIndex: 'encryptCurrHouseLoanInterestAmt',
                        key: 'encryptCurrHouseLoanInterestAmt',
                        width: 120,
                        columnType: 2,
                        render: t => <NumberTypeTd value={t} />,
                        align: 'right'
                    }
                ]
            },
            {
                title: '住房租金',
                width: 120,
                align: 'right',
                children: [
                    {
                        title: '当月金额',
                        dataIndex: 'encryptCurrHouseLeaseAmt',
                        key: 'encryptCurrHouseLeaseAmt',
                        width: 120,
                        columnType: 2,
                        render: t => <NumberTypeTd value={t} />,
                        align: 'right'
                    }
                ]
            },
            {
                title: '赡养老人',
                width: 120,
                align: 'right',
                children: [
                    {
                        title: '当月金额',
                        dataIndex: 'encryptCurrRaiseOldAmt',
                        key: 'encryptCurrRaiseOldAmt',
                        width: 120,
                        columnType: 2,
                        render: t => <NumberTypeTd value={t} />,
                        align: 'right'
                    }
                ]
            }
        ]
    }
];

// 基础信息部分内容格式化
const filterMap = {
    startDate: val => moment(val).format('YYYY-MM-DD'),
    birthday: val => moment(val).format('YYYY-MM-DD'),
    prAcquisitionDate: val => moment(val).format('YYYY-MM-DD'),
    housePlace: val => housePlaceEnum.getShowName(val),
    sex: val => sexEnum.getShowName(val)
};

// 基础信息中转，无数据时显示--
const baseInfoFilter = (val, key) => {
    if (val === '' || isNil(val)) {
        return <EmptyPlaceHolder />;
    }
    if (key && filterMap[key]) {
        return filterMap[key](val);
    }
    return val;
};

//  百分比设置
const QuestionTitle = ({ text, title }) => (
    <>
        {text}
        <Tooltip title={title} placement="top">
            <Icon type="question-circle-o" className={styles.questionIcon} />
        </Tooltip>
    </>
);

// 金额格式化
const NumberTypeTd = ({ value }) => (
    <span className={styles.currency} title={value}>
        <EmptyPlaceHolder value={numberFormat(value, '')} />
    </span>
);

export { HISTORY_RECORD_LIST, baseInfoOfCountry, baseInfoFilter, QuestionTitle, NumberTypeTd };
